<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
    <link rel="stylesheet" href="/layui-v2.4.5/layui/css/layui.css"  media="all">
    <style>
        .layui-table-cell {
            height: 36px;
            line-height: 28px;
            padding: 0 15px;
            position: relative;
            box-sizing: border-box;
        }
    </style>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div class="demoTable">



    <label class="layui-form-label" style="width: 100px;margin-top: 30px"><span>订单查询 :</span></label>
    <div class="layui-input-inline" style="width: 80%;margin-top: 30px">
        <div style="margin-bottom: 20px;display: flex;justify-content: space-between;width: 100%">
            <input type="text" name="visitPhone" placeholder="请输入手机号" id="visitPhone"  class="layui-input" style=" margin-right:20px" value="${visitPhone}">

            <input type="text" name="checkCode" placeholder="请输入核销码" id="checkCode"  class="layui-input" style="margin-right:20px" value="${checkCode}">

            <input type="text" name="shop" placeholder="请输入管理员凭证" id="shop"  class="layui-input" style="margin-right:20px" value="${shop}">
        </div>
       <div style="margin-bottom: 20px;display: flex;justify-content: space-between;width: 100%">
           <input type="text" name="personType" placeholder="请输入门票类型" id="personType"  class="layui-input" style="margin-right:20px" value="${personType}">

           <input type="text" name="startTime" id="date"  placeholder="选择起始日期"  class="layui-input" style="margin-right:20px" value="${startTime}">

           <input type="text" name="overtTime" id="date1"  placeholder="选择结束日期" class="layui-input" style="margin-right:20px" value="${overTime}">
       </div>



        <select class="layui-input" name="appId" id="checkStatus" style="width: 31.5%">
            <option value="">核销类型</option>
            <option class="layui-input" value="0">已核销 </option>
        </select>


    </div>

    <button class="layui-btn" data-type="reload">搜索</button>


</div>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script src="/layui-v2.4.5/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use(['form', 'table', 'laydate'], function(){
        var table = layui.table;
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        laydate.render({
            elem: '#date'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#date1'
            ,type:'datetime'
        });



        table.render({
            elem: '#test'
            ,url:getPath()+'/order/orderManagement'
            ,toolbar: '#toolbarDemo'
            ,title: '用户数据表'
            ,limit:10
            ,cols: [[

                //  {field:'id', title:'ID', width:80, fixed: 'left',type:'hide', unresize: true, sort: true}
                {field:'id', title:'订单ID', width:120, edit: 'text'}
                ,{field:'money', title:'金额', width:120, edit: 'text'}
                ,{field:'memberName', title:'会员名称', width:150, edit: 'text', templet: function(res){
                        return '<em>'+ res.memberName +'</em>'
                    }
                }

                ,{field:'hexiao', title:'核销操作',align:'center', width:120,templet: function(res){
                        console.log(res)
                        var tempId=res.id;
                        var checkStatus=res.checkStatus;
                        console.log(checkStatus)
                        if('0'==checkStatus){
                            return '<em>'+ "已核销" +'</em>'
                        }

                        if(res.checkStatus=='1') {
                            return '<button   onclick=checkOrder("' + tempId + '") class="layui-btn layui-btn-warm">核销</button>'
                        }

                    }}
                ,{field:'joinTime', title:'发货',align:'center', width:120,templet: function(res){
                        console.log(res)
                        var tempId=res.id;
                        var deliverystatus=res.deliverystatus;
                        console.log(deliverystatus)
                        if('1'==deliverystatus){
                            return '<em>'+ "已发货" +'</em>'
                        }
                        if(res.state=='4'){
                            return '<em>'+ "" +'</em>'
                        }

                        if(res.state=='1') {
                            return '<button   onclick=fahuo("' + tempId + '") class="layui-btn layui-btn-warm">发货</button>'
                        }
                        if(res.state=='0'){
                            return '<em>'+ "" +'</em>'
                        }

                    }}
                ,{field:'visitName', title:'购票人', width:180, edit: 'text', sort: true}
                ,{field:'tel', title:'电话号码', width:180, edit: 'text', sort: true}
                ,{field:'checkCode', title:'核销码', width:180, edit: 'text', sort: true}
                ,{field:'checkStatus', title:'核销状态', width:180, edit: 'text', sort: true}
                ,{field:'ticketName', title:'商品名称', width:200}
                ,{field:'number', title:'商品数量',width:160}
                ,{field:'createTime', title:'购买时间', width:180}
                ,{field:'endTime', title:'核销结束时间', width:180}
                ,{field:'state', title:'购票类型', width:90,templet: function(res){

                        return '<em>' + "电子票" + '</em>'

                    }
                }


                ,{field:'state', title:'订单状态', width:90,templet: function(res){
                        if(res.state=='0'){
                            return '<em>' + "未付款" + '</em>'
                        }else if(res.state=='1'){
                            return '<em>' + "已付款" + '</em>'
                        }else if(res.state=='2'){
                            return '<em>' + "已付款" + '</em>'
                        }else if(res.state=='3'){
                            return '<em>' + "已完成" + '</em>'
                        }else if(res.state=='4'){
                            return '<em>' + "已退款" + '</em>'
                        }
                    }
                }
                // , {field: 'checkStatus', title: '核销状态', width: 90, templet: function (res) {
                //         if (res.checkStatus == '0') {
                //             return '<em>' + "已核销" + '</em>'
                //         } else if (res.checkStatus == '1') {
                //             return '<em>' + "未核销" + '</em>'
                //         }
                //     }
                // }

                // , {field: 'checkStatus', title: '人员类型', width: 90, templet: function (res) {
                //         if (res.personType == '0') {
                //             return '<em>' + "儿童票" + '</em>'
                //         } else if (res.checkStatus == '1') {
                //             return '<em>' + "成人票" + '</em>'
                //         }
                //     }
                // }
                ,{field:'fenxiaoName', title:'分销商', width:150, edit: 'text', templet: function(res){
                        if(res.fenxiaoName==null){
                            return '<em>'+ "" +'</em>'
                        }
                        return '<em>'+ res.fenxiaoName +'</em>'
                    }
                }
                // ,{field:'joinTime', title:'发货',align:'center', width:120,templet: function(res){
                //         console.log(res)
                //         var tempId=res.id;
                //         var deliverystatus=res.deliverystatus;
                //         console.log(deliverystatus)
                //         if('1'==deliverystatus){
                //             return '<em>'+ "已发货" +'</em>'
                //         }
                //         if(res.state=='4'){
                //             return '<em>'+ "" +'</em>'
                //         }
                //
                //         if(res.state=='1') {
                //             return '<button   onclick=fahuo("' + tempId + '") class="layui-btn layui-btn-warm">发货</button>'
                //         }
                //         if(res.state=='0'){
                //             return '<em>'+ "" +'</em>'
                //         }
                //
                //
                //
                //
                //     }}
                // ,{field:'hexiao', title:'核销操作',align:'center', width:120,templet: function(res){
                //         console.log(res)
                //         var tempId=res.id;
                //         var checkStatus=res.checkStatus;
                //         console.log(checkStatus)
                //         if('0'==checkStatus){
                //             return '<em>'+ "已核销" +'</em>'
                //         }
                //
                //         if(res.checkStatus=='1') {
                //             return '<button   onclick=checkOrder("' + tempId + '") class="layui-btn layui-btn-warm">核销</button>'
                //         }
                //
                //     }}

                // ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,id: 'testReload'
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    layer.open({
                        type: 2,
                        title:"添加商户",
                        shadeClose:true,
                        offset: '30px',
                        area: ['75%', '75%'],
                        content: '/shop/enterAddcoupon',
                        end:function () {
                            window.location.reload();
                        }
                    });

                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                var dataStr=JSON.stringify(data);
                console.log(dataStr)
                layer.open({
                    type: 2,
                    title:"添加商户",
                    shadeClose:true,
                    offset: '30px',
                    area: ['75%', '75%'],
                    content: '/shop/enterAddcoupon?id='+data.id,
                    end:function () {
                        window.location.reload();
                    }
                });


            }
        });

        var $ = layui.$, active = {
            reload: function(){
                var demoReload = $('#demoReload');
                var type=$("#typeId").val()
                var visitPhone=$("#visitPhone").val()
                var personType=$("#personType").val()
                var startTime=$("#date").val()
                var overTime=$("#date1").val()
                var checkStatus=$("#checkStatus").val()

                var shop=$("#shop").val()
                var checkCode=$("#checkCode").val()
                var endTime=$("#endTime").val()
                var id=$("#id").val()
                var tel=$("#tel").val()
                var fenxiaoName=$("#fenxiao").val()   //分销商
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        key: demoReload.val(),
                        type: type,
                        visitPhone:visitPhone,
                        personType:personType,
                        startTime:startTime,
                        overTime:overTime,
                        shop:shop,
                        checkCode:checkCode,
                        checkStatus:checkStatus,
                        id:id,
                        tel:tel,
                        fenxiaoName: fenxiaoName
                    }
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            var checkCode=$(this).data('checkCode');
            var visitPhone=$(this).data('visitPhone');
            var startTime=$(this).data('startTime');
            var overTime=$(this).data('overTime');
            var shop=$(this).data('shop');
            var checkStatus=$(this).data('checkStatus');
            var personType=$(this).data('personType');
            var endTime=$("#endTime").val()
            var id=$(this).data('id')
            var tel=$(this).data('tel')
            var fenxiaoName=$(this).val('fenxiaoName')   //分销商
            active[type] ? active[type].call(this) : '';
            active[id]?active[id].call(this):'';
            active[checkCode]?active[checkCode].call(this):'';
            active[shop]?active[shop].call(this):'';
            active[visitPhone]?active[visitPhone].call(this):'';
            active[personType]?active[personType].call(this):'';
            active[checkStatus]?active[checkStatus].call(this):'';
            active[endTime]?active[endTime].call(this):'';
            active[tel]?active[tel].call(this):'';
            active[fenxiaoName] ? active[fenxiaoName].call(this) : '';

        });




        $(function () {
            $.ajax({
                url: '/order/fenxiaoMember',
                type: 'POST', //GET
                async: true,    //或false,是否异步
                data: $("#myForm").serialize(),
                timeout: 5000,    //超时时间
                dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend: function (xhr) {
                    /*console.log(xhr)
                     console.log('发送前')*/
                },
                success: function (data) {
                    console.log(data)
                    var item="<option value=\"\">选择分销商搜索</option>"
                    if(data){

                        for(var i=0;i<data.length;i++){
                            if(data[i].id!=null) {
                                item += "<option value=\"" + data[i].id + "\">" + data[i].name + "</option>"
                            }
                        }

                    }

                    $("#fenxiao").html(item)



                    form.render();


                },

            });
        })



    });


    /**
     * 项目路径
     */

    function getPath(){
        //获取当前网址，如： http://localhost:80/ybzx/index.jsp
        var curPath=window.document.location.href;
        //获取主机地址之后的目录，如： ybzx/index.jsp
        var pathName=window.document.location.pathname;
        var pos=curPath.indexOf(pathName);
        //获取主机地址，如： http://localhost:80
        var localhostPaht=curPath.substring(0,pos);
        //获取带"/"的项目名，如：/ybzx
        var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
        //return(localhostPaht+projectName);
        var path2= localhostPaht+projectName;
        return localhostPaht;
    }

    function checkOrder(id) {

        $.ajax({
            url: '/order/checkOrder',
            type: 'POST', //GET
            async: true,    //或false,是否异步
            data: {
                orderId: id
            },
            timeout: 5000,    //超时时间
            dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend: function (xhr) {
                /*console.log(xhr)
                 console.log('发送前')*/
            },
            success: function (data) {

                layer.msg("核销成功")
                setTimeout(function () {

                    // document.getElementById(".demoTable .layui-btn").click()
                    $('.demoTable .layui-btn').click()


                },1000)




            },

        });


    }
    function fahuo(id) {

        $.ajax({
            url: '/order/delivergoods',
            type: 'POST', //GET
            async: true,    //或false,是否异步
            data: {
                orderId: id
            },
            timeout: 5000,    //超时时间
            dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend: function (xhr) {
                /*console.log(xhr)
                 console.log('发送前')*/
            },
            success: function (data) {

                layer.msg("发货成功")
                setTimeout(function () {

                    // document.getElementById(".demoTable .layui-btn").click()
                    $('.demoTable .layui-btn').click()


                },1000)




            },

        });


    }

</script>

</body>
</html>